package com.gitee.wsl.compose.chart.frond

import androidx.compose.ui.geometry.Offset
import com.gitee.wsl.unit.angle.AngleUnit

/**
 * Specifies positioning values for a Pie Chart slice label.
 */
 sealed interface LabelPosition

/**
 * Specifies positioning values for a Pie Chart slice's external label (the label that is outside the perimeter of
 * the pie).
 *
 * [position] specifies the offset of the label's top-left corner relative to the center of the Pie Chart, which
 * is at the coordinate (0, 0), with positive values down and to the right.
 *
 * [anchorPoint] specifies the point on the label to which a connector line should be drawn, in the same coordinate
 * system as [position].
 *
 * [anchorAngle] specifies the angle at which the connector line should attach to the label at [anchorPoint], where
 * 0 degrees is to the right and angles increase in the clockwise direction.
 */
 data class ExternalLabelPosition(
    val position: Offset,
    val anchorPoint: Offset,
    val anchorAngle: AngleUnit
) : LabelPosition

/**
 * Specifies positioning for a Pie Chart slice's internal label (the label is placed within the pie slice).
 *
 *  [position] specifies the offset of the label's top-left corner relative to the center of the Pie Chart, which
 *  is at the coordinate (0, 0), with positive values down and to the right.
 */
 data class InternalLabelPosition(val position: Offset) : LabelPosition

/**
 * Specifies a label that is not positioned, and should not be displayed. This is used, for example, when
 * only internal slice labels should be used and a label does not fit within its slice.
 */
 data object None : LabelPosition

internal fun LabelPosition.getPositionOrNull(): Offset? {
    return when (this) {
        is ExternalLabelPosition -> position
        is InternalLabelPosition -> position
        is None -> null
    }
}